import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';

class SettingsSection extends StatelessWidget {
  final String title;
  final List<Widget> children;
  final double animationDelay;

  const SettingsSection({
    Key? key,
    required this.title,
    required this.children,
    this.animationDelay = 0.0,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PlayAnimationBuilder<double>(
      tween: Tween<double>(begin: 0.0, end: 1.0),
      delay: Duration(milliseconds: (animationDelay * 300).toInt()),
      duration: const Duration(milliseconds: 600),
      curve: Curves.easeOutQuad,
      builder: (context, value, child) {
        return Opacity(
          opacity: value,
          child: Transform.translate(
            offset: Offset(-20 * (1 - value), 0),
            child: child,
          ),
        );
      },
      child: Padding(
        padding: const EdgeInsets.only(bottom: 24, top: 8),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
              child: Text(
                title,
                style: const TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Color(0xFF3F5491),
                ),
              ),
            ),
            ...List.generate(
              children.length,
              (index) {
                final child = children[index];
                // تەڭشەش تۈرلىرى ئۈچۈن كىچىكتۈرۈش ۋاقتىنى بەلگىلەش
                if (child is StatelessWidget) {
                  try {
                    // SettingsItem ياكى SettingsToggleItem بولسا، delay قوشىمىز
                    final childWithDelay = (child as dynamic);
                    if (childWithDelay.animationDelay != null) {
                      return childWithDelay.copyWith(
                        animationDelay: animationDelay + 0.2 + (index * 0.2),
                      );
                    }
                  } catch (e) {
                    // copyWith مېتودى تېپىلمىسا، ئەسلى Widget نى قايتۇرىمىز
                  }
                }
                return child;
              },
            ),
          ],
        ),
      ),
    );
  }
} 